//
// Created by Rory on 2020/10/28.
//

#include "binarytree.h"

ThreadNode* InThreadNode(ThreadNode* currentNode, ThreadNode** pre){
    if (currentNode != NULL){
        InThreadNode(currentNode->lchild, pre);//线索化左孩子结点

        //线索化当前结点
        if(currentNode->lchild == NULL){//建立前驱线索
            currentNode->lchild = (*pre);
            currentNode ->lthread = true;
        }
        if((*pre) != NULL && (*pre)->rchild == NULL){//建立前驱结点的后继线索
            (*pre)->rchild = currentNode;
            (*pre)->rthread = true;
        }
        (*pre) = currentNode;

        InThreadNode(currentNode->rchild, pre);//线索化右孩子结点

    }
}


void CreateInThreadTree(ThreadTree* tree){
    if(tree != NULL){
        ThreadNode* pre = NULL;
        InThreadNode(tree,&pre);
        pre->rchild = NULL;
        pre->rthread = true;
    }
}